//
//  EmotionTextAttachment.swift
//  AnimotionKeyboard
//
//  Created by xxy on 16/6/3.
//  Copyright © 2016年 xxy. All rights reserved.
//

import UIKit

/// 表情文本附件
class EmotionTextAttachment: NSTextAttachment {
    var chs: String?
    /// 类方法.使用指定的表情,生成属性文本,并在附件中记录表情描述
    class func imageText(em: Emotion,font: UIFont) -> NSAttributedString{
        //1:创建图片属性文本
        let attachment = EmotionTextAttachment()
        attachment.chs  = em.chs
        
        attachment.image = UIImage(contentsOfFile: em.imagePath)
        let lineHeight  = font.lineHeight
        attachment.bounds = CGRectMake(0, -4, lineHeight, lineHeight)
        let imageAtt = NSMutableAttributedString(attributedString: NSAttributedString(attachment: attachment))
        //设置字体
        imageAtt.addAttribute(NSFontAttributeName, value: font, range:NSRange(location: 0,length: 1) )
        return imageAtt
    }
}
